package com.shire.shire_interface.service.group.impl;

import com.shire.shire_interface.dao.group.WxGroupQrcodeDao;
import com.shire.shire_interface.model.group.WxGroupQrcode;
import com.shire.shire_interface.model.group.WxGroupQrcodeExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class WxGroupQrcodeService {
    @Resource
    private WxGroupQrcodeDao groupQrcodeDao;

    public WxGroupQrcode getGroupQrcode(String wxAccount, String groupNo){
        WxGroupQrcodeExample example = new WxGroupQrcodeExample();
        example.createCriteria().andWxaccountEqualTo(wxAccount).andGroupnoEqualTo(groupNo);
        List<WxGroupQrcode> groupQrcodeList = groupQrcodeDao.selectByExampleWithBLOBs(example);

        if (groupQrcodeList.size()>0)
            return groupQrcodeList.get(0);

        return null;
    }

    public WxGroupQrcode getSlimGroupQrcode(String wxAccount, String groupNo){
        WxGroupQrcodeExample example = new WxGroupQrcodeExample();
        example.createCriteria().andWxaccountEqualTo(wxAccount).andGroupnoEqualTo(groupNo);
        List<WxGroupQrcode> groupQrcodeList = groupQrcodeDao.selectByExample(example);

        if (groupQrcodeList.size()>0)
            return groupQrcodeList.get(0);

        return null;
    }

    public int saveGroupQrcode(WxGroupQrcode qrcode){
        if (qrcode.getId() == null){
            qrcode.setCreatetime(new Date());
            return groupQrcodeDao.insert(qrcode);
        }else {
            qrcode.setUdpatetime(new Date());
            return groupQrcodeDao.updateByPrimaryKeyWithBLOBs(qrcode);
        }
    }
}
